//初始化rem
function initRem() {
	var innerWidth = window.innerWidth;
	if(innerWidth >= 800) {
		innerWidth = 800;
	}
	rem = innerWidth / 7.5 + 'px';
	document.documentElement.style.fontSize = rem;
}
initRem();
////监听页面变化
window.onresize = function() {
	initRem();
	//		window.location.reload();
}

//输入账号
var tel=false;
function frmname(name) {
	var reg1=/^\s*$/;
	//如果是空字符串
	if (reg1.test($(name).val())){
		$(name).siblings("h4").html("用户名不能为空!");
		return;
	}
	tel=true;
	$(name).siblings("h4").html("");
	return true;
}
//输入密码
function frmpwd(name) {
	var reg1=/^\s*$/;
	var reg=/^\d{6}$/;
	//如果是空字符串
	if (reg1.test($(name).val()))
	{
		$(name).siblings("h4").html("密码不能为空!");
		return;
	}
	//验证格式
	if (!reg.test($(name).val())) {
		$(name).siblings("h4").html("密码格式错误");
		return;
	}
	$(name).siblings("h4").html("");
	return true;
}

//再次输入密码
function againpwd(name,prev) {
	var reg1=/^\s*$/;
	//如果是空字符串
	if (reg1.test($(name).val()))
	{
		$(name).siblings("h4").html("密码不能为空!");
		return;
	}
	//验证格式
	if ($(name).val()!=$(prev).val()) {
		$(name).siblings("h4").html("密码不一致");
		return;
	}
	$(name).siblings("h4").html("");
	return true;
}
//判断不为空
function noempty(name) {
	var reg1=/^\s*$/;
	//如果是空字符串
	if (reg1.test($(name).val()))
	{
		$(name).siblings("h4").html("输入不能为空!");
		return;
	}
	$(name).siblings("h4").html("");
	return true;
}

//输入身份证号码
function card(name){
	var reg1=/^\s*$/;
	var reg=/^[0-9]{17}[0-9a-zA-Z]$/;
	//如果是空字符串
	if (reg1.test($(name).val())){
		$(name).siblings("h4").html("身份证号不能为空!");
		return;
	}else if (!reg.test($(name).val())){
		$(name).siblings("h4").html("身份证号格式错误!");
		return;
	}
	$(name).siblings("h4").html("");
	return true;
	//sessionStorage.setItem("card", "1");
}
//输入账号-手机号
function frmtel(name) {
	var reg1=/^\s*$/;
	var reg=/^1[3589][0-9]{9}$/;
	//如果是空字符串
	if (reg1.test($(name).val())){
		$(name).siblings("h4").html("用户名不能为空!");
		return;
	}else if (!reg.test($(name).val())){
		console.log("1111")
		$(name).siblings("h4").html("手机号格式错误!");
		return;
	}
	tel=true;
	$(name).siblings("h4").html("");
	return true;
	//sessionStorage.setItem("tel", "1");
}

window.onload = function() {
//弹窗
	!function(){
		function id(a){return window.parent.document.getElementById(a);}
		if(!Boolean(id('xxy-addDom'))){
			try{
				var div=window.parent.document.createElement('div');
				div.id='xxy-addDom';
				window.parent.document.body.appendChild(div);
			}catch(e){
				console.error('请把脚本放到body标签下面(不是底部!)--xxy');
			}
		}
		if(typeof window.parent.xxy=='object'){
			console.error('请关闭xxy的全局对象--xxy');
			return false;
		}
		window.xxy={
			s:function(e){
				e.preventDefault();
			}, 
			/**
			 * 
			 * @param {Object} a 提示文字
			 * @param {Object} b 内容
			 * @param {Object} d 回调函数
			 */
			popup:function(a,b,d){
				document.documentElement.style.overflow='hidden';
				document.body.style.overflow='hidden';
				var cs=arguments,
					title='提示',
					inner='',
					deon_text='确认',
					cancal_text='取消',
					fun=false;
				function callback(a,b){
					for(var i=0;i<a.length;i++){
						if(typeof a[i]=='function'){
							a[i](b);
							break;
						}
					}
				}
				for(var i=0;i<arguments.length;i++){
					if(typeof arguments[i]=='function'){
						fun=true;
					}
				}
				if(!fun){
					if(cs.length==1){
						inner=cs[0];
					}else{
						if(cs.length==2){
							title=cs[0];
							inner=cs[1];
						}
						if(cs.length==3){
							colole.error('参数错误！--xxy');
						}
						if(cs.length==4){
							title=cs[0];
							inner=cs[1];
							deon_text=cs[2];
							cancal_text=cs[3];
						}
					}
				}else{
					if(cs.length==2){
						inner=cs[0];
					}else{
						if(cs.length==3){
							title=cs[0];
							inner=cs[1];
						}
						if(cs.length==4){
							inner=cs[0];
							deon_text=cs[1];
							cancal_text=cs[2];
						}
						if(cs.length==5){
							title=cs[0];
							inner=cs[1];
							deon_text=cs[2];
							cancal_text=cs[3];
						}
					}
				}
				var c=[
						'<div class="xxy-popup-box" id="xxy-popup-box">',
							'<div class="inner">',
								'<div class="inner_box">',
									'<div class="xxy-popup-inner">',
										'<div class="xxy-popup-title"> <i class="iconfont icon-tishi"></i> ',title,
											'<i id="xxy-popup-off" class="off icon iconfont icon-cha" id="cash-off"></i>',
										'</div>',
										'<div id="xxy_popup_inner_print" class="print">',inner,'</div>',
									'</div>',
									'<div class="or">',
										'<button class="xxy-popup-done" id="xxy-popup-done">',deon_text,'</button>',
										'<button class="xxy-popup-cancal" id="xxy-popup-cancal">',cancal_text,'</button>',
									'</div>',
								'</div>',
							'</div>',
						'</div>'
					].join('');
				//document.body.innerHTML+=c; 直接插入body会导致body dom重新生成，虽然是那个div，但是dom对象已经变了，会导致body下所有的dom事件消失
				id('xxy-addDom').innerHTML+=c;			
				document.getElementById('xxy_popup_inner_print').ontouchmove=function(e){
					e.stopPropagation();
				};
				try{
					window.parent.document.body.addEventListener('touchmove',xxy.s,false);	
				}catch(e){
					function iexx(){
						var child=id('xxy-popup-box');
						child.parentNode.removeChild(child);
						try{
							window.parent.document.body.removeEventListener('touchmove',xxy.s,false);
						}catch(e){
							//手机没有ie所以不用处理
						}
						document.documentElement.style.overflow='auto';
					}
					/*兼容ie*/
					id('xxy-popup-done').onclick=function(){
						callback(cs,0);	
						iexx();
					}
					id('xxy-popup-cancal').onclick=function(){
						callback(cs,1);	
						iexx();
					}
					return false;
				}
				id('xxy-popup-box').onclick=function(e){
					var e=e.target,
						done='xxy-popup-done',
						cancal='xxy-popup-cancal';
					if(e.id==done||e.id==cancal||e.id=='xxy-popup-off'){
						var child=id('xxy-popup-box');
						child.parentNode.removeChild(child);
						window.parent.document.body.removeEventListener('touchmove',xxy.s,false);
						document.documentElement.style.overflow='auto';
						document.body.style.overflow='auto';
						if(e.id==done){
								callback(cs,0);			
							}
							if(e.id==cancal){
								callback(cs,1)	
							}
						}
				};
				//if(window.navigator.userAgent.indexOf('iPhone')!=-1){
				//	//('，，，蛋疼的苹果会给fiexd的高度设置为父级窗口。');
				//}
			},
			alert:function(a,b,f){
				var callBack=false;
				for(var i=0;i<arguments.length;i++){
					if(typeof a[i]=='function'){
						callBack=true;
					}
				}
				try{
					console.log(b.length)
					if(callBack){
						xxy.popup(a,b,f);
					}else{
						xxy.popup(a,b);
					}
				}catch(e){
					if(callBack){
						xxy.popup(a,f);
					}else{
						xxy.popup(a);
					}
				}
				var button_=window.parent.document.querySelector('#xxy-addDom #xxy-popup-cancal'),
					button_child2=window.parent.document.querySelector('#xxy-addDom .xxy-popup-box button:nth-child(1)');
					off_=id('xxy-popup-off').style.display='none';
					button_.style.width='100%';
					button_.innerHTML='确认';
					button_.style.marginLeft='auto';
					button_.style.marginRight='auto';
					button_.style.display='block';
					button_child2.style.display='none';
				//tips:不用当心下次影响popup  当元素Dom关闭后，对应的属性自然会删除。只有css才是永远的渲染。
			},
			toast:function(a,b){
				var time=(arguments[1]?b:2500)+1000;
				var c=[
					'<div id="xxy-toast" class="xxy-toast">',a,'</div>'
				].join('');
				id('xxy-addDom').innerHTML+=c;
				window.setTimeout(function(){
					var child=id('xxy-toast');
					try{
						child.style.background='rgba(0,0,0,0)';
						child.style.color='rgba(0,0,0,0)';
					}catch(e){
						child.style.display='none';
					}
				},time-2000);
				window.setTimeout(function(){
					var child=id('xxy-toast');
					child.parentNode.removeChild(child);
				},time);
			}
		};
	}();
	
	!function(){
		var div=window.parent.document.createElement('div');
		div.id='xxone-addDom';
		window.parent.document.body.appendChild(div);
		function id(a){return window.parent.document.getElementById(a);}
		if(typeof window.parent.xxone=='object'){
			return false;
		}
		window.xxone={
			s:function(e){
				e.preventDefault();
			},
			popup:function(a,b,d){
				var cs=arguments,
					title='提示',
					inner='',
					deon_text='确认',
					fun=false;
				function callback(a,b){
					for(var i=0;i<a.length;i++){
						if(typeof a[i]=='function'){
							a[i](b);
							break;
						}
					}
				}
				for(var i=0;i<arguments.length;i++){
					if(typeof arguments[i]=='function'){
						fun=true;
					}
				}
				if(!fun){
					if(cs.length==1){
						inner=cs[0];
					}else{
						if(cs.length==2){
							title=cs[0];
							inner=cs[1];
						}
						if(cs.length==3){
							title=cs[0];
							inner=cs[1];
							deon_text=cs[2];
						}
					}
				}else{
					if(cs.length==2){
						inner=cs[0];
					}else{
						if(cs.length==3){
							title=cs[0];
							inner=cs[1];
						}
						if(cs.length==4){
							inner=cs[0];
							deon_text=cs[1];
						}
						if(cs.length==5){
							title=cs[0];
							inner=cs[1];
							deon_text=cs[2];
						}
					}
				}
				var c=[
					'<div class="xxone-popup-box" id="xxone-popup-box">',
					'<div class="inner">',
					'<div class="xxone-popup-inner">',
					'<div class="xxone-popup-title"> <i class="iconfont icon-tishi"></i> ',title,
					'<i id="xxone-popup-off" class="off icon iconfont icon-cha" id="cash-off"></i>',
					'</div>',
					'<div class="print">',inner,'</div>',
					'</div>',
					'<div class="or">',
					'<button class="xxone-popup-done" id="xxone-popup-done">',deon_text,'</button>',
					'</div>',
					'</div>',
					'</div>'
				].join('');
				//document.body.innerHTML+=c; 直接插入body会导致body dom重新生成，虽然是那个div，但是dom对象已经变了，会导致body下所有的dom事件消失
				id('xxone-addDom').innerHTML+=c;
				window.parent.document.body.addEventListener('touchmove',xxone.s,false);
				id('xxone-popup-box').onclick=function(e){
					var e=e.target,
						done='xxone-popup-done';
					if(e.id==done||e.id=='xxone-popup-off'){
						var child=id('xxone-popup-box');
						child.parentNode.removeChild(child);
						window.parent.document.body.removeEventListener('touchmove',xxone.s,false);
						if(e.id==done){
							callback(cs,0);
						}
					}
				};
			},
			toast:function(a,b){
				var time=(arguments[1]?b:2500)+1000;
				var c=[
					'<div id="xxone-toast" class="xxone-toast">',a,'</div>'
				].join('');
				id('xxone-addDom').innerHTML+=c;
				window.setTimeout(function(){
					var child=id('xxone-toast');
					child.style.background='rgba(0,0,0,0)';
					child.style.color='rgba(0,0,0,0)';
				},time-2000);
				window.setTimeout(function(){
					var child=id('xxone-toast');
					child.parentNode.removeChild(child);
				},time);
			}
		};
	}();
	/**
	 *微信露底
	 */
	!function(){
		function ld(ev) { ev.preventDefault(); }
		var add=false;
		document.body.addEventListener("touchstart",function(e){
			y1=e.changedTouches[0].clientY;
			add=true;
		});
		document.body.addEventListener("touchend",function(e){
			document.body.removeEventListener("touchstart",ld);//clear
		});
		document.body.addEventListener("touchmove",function(e){
			e.stopPropagation();
			y=e.changedTouches[0].clientY;
			var l,fx=y<y1?'上':'下';
			if(y<y1){
				l=y1-y;
			}else{
				l=y-y1;
			}
			//console.log('原点：'+y1+'    当前：'+y+'   方向:'+fx+'   Y轴滑动相差值:'+l);
			if(l>30&&add){
				//console.log('Y轴有滑动');
				document.body.addEventListener('touchstart',ld);//add
				add=false;
			}
		});
	}();

}


